package com.bruan.exception;

import java.util.Scanner;

/***
 * 捕获异常 尝试修复
 */
public class ExceptionTest4 {
    public static void main(String[] args) {
        while (true) {
            try {
                System.out.println(getMoney());
                break;
            } catch (Exception e) {
                System.out.println("请你输入合法价格");
    //            throw new RuntimeException(e);
            }
        }
    }
    public static double getMoney(){
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入合适价格");
            double money = sc.nextDouble();
            if (money >= 0){
                System.out.println("价格收取成功");
                return money;
            }else{
                System.out.println("输入价格不合适");
            }
        }
    }
}
